﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Text.RegularExpressions;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CategoryMenu : BaseModule, IPortable
    {
        public bool _chkHideSubMenu;
        public bool _chkPatchWork;
        public int _ddlDefaultCategory;
        [AccessedThroughProperty("dlCategoryMenu")]
        private DataList _dlCategoryMenu;
        [AccessedThroughProperty("dlRootMenu")]
        private DataList _dlRootMenu;
        [AccessedThroughProperty("lblBreadcrumbs")]
        private PlaceHolder _lblBreadcrumbs;
        [AccessedThroughProperty("phRootHead")]
        private PlaceHolder _phRootHead;
        [AccessedThroughProperty("phSecSep1")]
        private PlaceHolder _phSecSep1;
        [AccessedThroughProperty("phSecSep2")]
        private PlaceHolder _phSecSep2;
        [AccessedThroughProperty("phSecSep3")]
        private PlaceHolder _phSecSep3;
        [AccessedThroughProperty("phSubHead")]
        private PlaceHolder _phSubHead;
        [AccessedThroughProperty("phTreeHead")]
        private PlaceHolder _phTreeHead;
        [AccessedThroughProperty("phTreeMenu")]
        private PlaceHolder _phTreeMenu;
        public Hashtable _SelectedCategories;
        public bool _SubMenuOnly;
        public int _TabId;
        public string _txtColumns;
        public string _txtCSS;
        public string _txtSubHeadHtml;
        public string _txtSubLeftHtml;
        public string _txtSubMenuSep;
        public string _txtSubNameTemplate;
        public string _txtSubRightHtml;
        public string _txtSubSelectCSS;
        public string _txtThumbnailSize;
        private int CatID;

        public CategoryMenu()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
            this.CatID = 0;
            this._SubMenuOnly = false;
            this._TabId = -1;
            this._chkPatchWork = false;
        }

        private string BuildAccordionMenu(ArrayList aryList, string htmlText, int ParentID, int AccordionLevel)
        {
            IEnumerator enumerator=null;
            string str3 = "";
            string str2 = "</ul>";
            AccordionLevel++;
            if (ParentID == 0)
            {
                str3 = str3 + "<ul id=\"NBStoreAccordion\" >";
            }
            else
            {
                str3 = str3 + "<ul>";
            }
            if (AccordionLevel > 1)
            {
                str3 = "";
                str2 = "";
            }
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                    if (((current.ParentCategoryID == ParentID) & !current.Archived) & !current.Hide)
                    {
                        string selectCSS = "";
                        if (AccordionLevel > 1)
                        {
                            htmlText = htmlText + "</li><li>";
                        }
                        else
                        {
                            htmlText = htmlText + "<li>";
                        }
                        if (ParentID == 0)
                        {
                            selectCSS = "nbstoremenuhead";
                            AccordionLevel = 0;
                        }
                        else
                        {
                            selectCSS = "nbstoremenusub" + AccordionLevel.ToString();
                        }
                        htmlText = htmlText + this.BuildHtmlCatLink(Conversions.ToString(this.Settings["txtAccordionNameTemplate"]), Conversions.ToString(this.Settings["txtAccordionLeftHtml"]), Conversions.ToString(this.Settings["txtAccordionRightHtml"]), selectCSS, current);
                        htmlText = htmlText + this.BuildAccordionMenu(aryList, "", current.CategoryID, AccordionLevel);
                        if (AccordionLevel <= 1)
                        {
                            htmlText = htmlText + "</li>";
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (htmlText != "")
            {
                htmlText = str3 + htmlText + str2;
            }
            return htmlText;
        }

        private string BuildBreadCrumbs(int CatID, ArrayList aryList)
        {
            int categoryID = CatID;
            string str6 = "";
            CategoryController controller = new CategoryController();
            string parentName = "";
            string categoryName = "";
            int firstNonEmptyChild = 0;
            string str = "";
            string str2 = "";
            do
            {
                if (categoryID > 0)
                {
                    NB_Store_CategoriesInfo category = controller.GetCategory(categoryID, SharedFunctions.GetCurrentCulture());
                    if (category != null)
                    {
                        if (Conversions.ToBoolean(this.Settings["chkHideBreadCrumbRoot"]) & (category.ParentName == ""))
                        {
                            categoryID = category.ParentCategoryID;
                        }
                        else
                        {
                            if (category.CategoryID == CatID)
                            {
                                categoryName = category.CategoryName;
                            }
                            parentName = category.ParentName;
                            categoryID = category.ParentCategoryID;
                            firstNonEmptyChild = categoryID;
                            if (Conversions.ToBoolean(this.Settings["chkSkipBlankCat"]))
                            {
                                firstNonEmptyChild = this.GetFirstNonEmptyChild(firstNonEmptyChild);
                            }
                            if (parentName == "")
                            {
                                parentName = DotNetNuke.Services.Localization.Localization.GetString("Root", this.LocalResourceFile);
                            }
                            if (Conversions.ToString(this.Settings["txtBreadCrumbSep"]) == "")
                            {
                                str2 = " &gt; ";
                            }
                            else
                            {
                                str2 = Conversions.ToString(this.Settings["txtBreadCrumbSep"]);
                            }
                            if (Versioned.IsNumeric(Conversions.ToString(this.Settings["lstProductTabs"])))
                            {
                                str6 = "<a href=\"" + DotNetNuke.Common.Globals.NavigateURL(Conversions.ToInteger(this.Settings["lstProductTabs"]), "", new string[] { "CatID=" + firstNonEmptyChild.ToString() }) + "\"" + str + ">" + parentName + "</a>" + str2 + str6;
                            }
                            else
                            {
                                str6 = "<a href=\"" + DotNetNuke.Common.Globals.NavigateURL(this._TabId, "", new string[] { "CatID=" + firstNonEmptyChild.ToString() }) + "\"" + str + ">" + parentName + "</a>" + str2 + str6;
                            }
                        }
                    }
                    else
                    {
                        categoryID = 0;
                    }
                }
            }
            while (categoryID > 0);
            if (str6 != "")
            {
                str6 = str6 + "<a href=\"" + DotNetNuke.Common.Globals.NavigateURL(this._TabId, "", new string[] { "CatID=" + CatID.ToString() }) + "\"" + str + ">" + categoryName + "</a>";
            }
            if (Conversions.ToString(this.Settings["txtBreadCrumbCSS"]) != "")
            {
                return ("<div class=\"" + Conversions.ToString(this.Settings["txtBreadCrumbCSS"]) + "\">" + str6 + "</div>");
            }
            return ("<div>" + str6 + "</div>");
        }

        private string BuildHtmlCatLink(string NameTemplate, string Lefthtml, string RightHtml, string SelectCSS, NB_Store_CategoriesInfo itemInfo)
        {
            int firstNonEmptyChild;
            string str4 = "";
            string strHtmlLink = "";
            string str5 = "";
            Regex regex = new Regex(@"\s*");
            string input = "";
            input = Strings.Replace(itemInfo.Message, "&lt;p&gt;&amp;#160;&lt;/p&gt;", "", 1, -1, CompareMethod.Binary);
            if (input != "")
            {
                input = Regex.Replace(input, @"\s*", "");
            }
            if ((Conversions.ToBoolean(this.Settings["chkSkipBlankCat"]) & (itemInfo.ProductCount == 0)) & (input == ""))
            {
                firstNonEmptyChild = this.GetFirstNonEmptyChild(itemInfo.CategoryID);
            }
            else
            {
                firstNonEmptyChild = itemInfo.CategoryID;
            }
            if (Versioned.IsNumeric(Conversions.ToString(this.Settings["lstProductTabs"])))
            {
                if (itemInfo.SEOName != "")
                {
                    strHtmlLink = SharedFunctions.GetProductListUrlByCatID(this.PortalId, Conversions.ToInteger(this.Settings["lstProductTabs"]), firstNonEmptyChild, itemInfo.SEOName, SharedFunctions.GetCurrentCulture());
                }
                else
                {
                    strHtmlLink = SharedFunctions.GetProductListUrlByCatID(this.PortalId, Conversions.ToInteger(this.Settings["lstProductTabs"]), firstNonEmptyChild, itemInfo.CategoryName, SharedFunctions.GetCurrentCulture());
                }
            }
            else if (itemInfo.SEOName != "")
            {
                strHtmlLink = SharedFunctions.GetProductListUrlByCatID(this.PortalId, this._TabId, firstNonEmptyChild, itemInfo.SEOName, SharedFunctions.GetCurrentCulture());
            }
            else
            {
                strHtmlLink = SharedFunctions.GetProductListUrlByCatID(this.PortalId, this._TabId, firstNonEmptyChild, itemInfo.CategoryName, SharedFunctions.GetCurrentCulture());
            }
            if (NameTemplate == "")
            {
                str5 = Lefthtml + itemInfo.CategoryName + RightHtml;
            }
            else
            {
                str5 = this.ReplaceLinkTokens(NameTemplate, Lefthtml, RightHtml, itemInfo, strHtmlLink);
            }
            if (str5.StartsWith("<a"))
            {
                return str5;
            }
            str4 = "<a href=\"" + strHtmlLink + "\" ";
            if (((itemInfo.CategoryID == this.CatID) | this._SelectedCategories.ContainsKey(itemInfo.CategoryID)) & (SelectCSS != ""))
            {
                str4 = str4 + "class=\"" + SelectCSS + "\"";
            }
            return ((str4 + ">" + str5) + "</a>");
        }

        private string BuildTreeMenu(ArrayList aryList, string htmlText, int ParentID, int LevelCount)
        {
            IEnumerator enumerator=null;
            string str3 = "";
            string str2 = "</ul>";
            if (ParentID == 0)
            {
                string str4 = Conversions.ToString(this.Settings["txtTreeCSS"]);
                if (str4 == "")
                {
                    str4 = "treeview";
                }
                str3 = str3 + "<ul id=\"NBStoreTreeMenu\" class=\"" + str4 + "\">";
            }
            else
            {
                str3 = str3 + "<ul>";
            }
            try
            {
                enumerator = aryList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                    if (((current.ParentCategoryID == ParentID) & !current.Archived) & !current.Hide)
                    {
                        htmlText = htmlText + "<li>";
                        htmlText = htmlText + this.BuildHtmlCatLink(Conversions.ToString(this.Settings["txtTreeNameTemplate"]), Conversions.ToString(this.Settings["txtTreeLeftHtml"]), Conversions.ToString(this.Settings["txtTreeRightHtml"]), Conversions.ToString(this.Settings["txtTreeSelectCSS"]), current);
                        if (LevelCount < 50)
                        {
                            htmlText = htmlText + this.BuildTreeMenu(aryList, "", current.CategoryID, LevelCount + 1);
                        }
                        htmlText = htmlText + "</li>";
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            if (htmlText != "")
            {
                htmlText = str3 + htmlText + str2;
            }
            return htmlText;
        }

        private void dlCategoryMenu_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            NB_Store_CategoriesInfo dataItem = (NB_Store_CategoriesInfo) e.Item.DataItem;
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                PlaceHolder holder = (PlaceHolder) e.Item.FindControl("phCatLink");
                if (holder != null)
                {
                    holder.Controls.Add(new LiteralControl(this.BuildHtmlCatLink(this._txtSubNameTemplate, this._txtSubLeftHtml, this._txtSubRightHtml, this._txtSubSelectCSS, dataItem)));
                }
            }
        }

        private void dlRootMenu_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            NB_Store_CategoriesInfo dataItem = (NB_Store_CategoriesInfo) e.Item.DataItem;
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                PlaceHolder holder = (PlaceHolder) e.Item.FindControl("phCatLink");
                if (holder != null)
                {
                    holder.Controls.Add(new LiteralControl(this.BuildHtmlCatLink(Conversions.ToString(this.Settings["txtRootNameTemplate"]), Conversions.ToString(this.Settings["txtRootLeftHtml"]), Conversions.ToString(this.Settings["txtRootRightHtml"]), Conversions.ToString(this.Settings["txtRootSelectCSS"]), dataItem)));
                }
            }
        }

        public string ExportModule(int ModuleID)
        {
            string str = string.Empty;
            return str;
        }

        private int GetFirstNonEmptyChild(int CategoryID)
        {
            ArrayList list = new CategoryController().GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture(), CategoryID, false, false);
            if (list.Count > 0)
            {
                if (((NB_Store_CategoriesInfo) list[0]).ProductCount != 0)
                {
                    return ((NB_Store_CategoriesInfo) list[0]).CategoryID;
                }
                if (((NB_Store_CategoriesInfo) list[0]).CategoryID != CategoryID)
                {
                    return this.GetFirstNonEmptyChild(((NB_Store_CategoriesInfo) list[0]).CategoryID);
                }
            }
            return CategoryID;
        }

        private void GetSelectedCategories(int CategoryID, ref Hashtable htList)
        {
            NB_Store_CategoriesInfo category = new CategoryController().GetCategory(CategoryID, SharedFunctions.GetCurrentCulture());
            if ((category != null) && !htList.ContainsKey(CategoryID))
            {
                htList.Add(CategoryID, category);
                if ((category.ParentCategoryID > 0) & (htList.Count < 20))
                {
                    this.GetSelectedCategories(category.ParentCategoryID, ref htList);
                }
            }
        }

        public void ImportModule(int ModuleID, string Content, string Version, int UserID)
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            if (!this._SubMenuOnly)
            {
                this._chkHideSubMenu = Conversions.ToBoolean(this.Settings["chkHideSubMenu"]);
                this._chkPatchWork = Conversions.ToBoolean(this.Settings["chkPatchWork"]);
                this._txtColumns = Conversions.ToString(this.Settings["txtColumns"]);
                this._txtSubLeftHtml = Conversions.ToString(this.Settings["txtSubLeftHtml"]);
                this._txtSubNameTemplate = Conversions.ToString(this.Settings["txtSubNameTemplate"]);
                this._txtSubRightHtml = Conversions.ToString(this.Settings["txtSubRightHtml"]);
                this._txtSubHeadHtml = Conversions.ToString(this.Settings["txtSubHeadHtml"]);
                this._txtSubSelectCSS = Conversions.ToString(this.Settings["txtSubSelectCSS"]);
                this._txtSubMenuSep = Conversions.ToString(this.Settings["txtSep"]);
                this._txtCSS = Conversions.ToString(this.Settings["txtCSS"]);
                this._txtThumbnailSize = Conversions.ToString(this.Settings["txtThumbnailSize"]);
                if (Versioned.IsNumeric(Conversions.ToString(this.Settings["ddlDefaultCategory"])))
                {
                    this._ddlDefaultCategory = Conversions.ToInteger(this.Settings["ddlDefaultCategory"]);
                }
                else
                {
                    this._ddlDefaultCategory = -1;
                }
                this._TabId = this.TabId;
            }
            if (this._txtThumbnailSize == "")
            {
                this._txtThumbnailSize = "100";
            }
            if (this.Settings["txtRootSep"] != null && this.Settings["txtRootSep"].ToString() != string.Empty)
            {
                this.dlRootMenu.SeparatorTemplate = new BaseDisplayTemplate(this.Server.HtmlDecode(Conversions.ToString(this.Settings["txtRootSep"])));
            }
            if (this._txtSubMenuSep != null && this._txtSubMenuSep != "")
            {
                this.dlCategoryMenu.SeparatorTemplate = new BaseDisplayTemplate(this.Server.HtmlDecode(this._txtSubMenuSep));
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                this.CatID = this._ddlDefaultCategory;
                int catID = this.CatID;
                if (this.Request.QueryString["CatID"] != null)
                {
                    if (Versioned.IsNumeric(this.Request.QueryString["CatID"]))
                    {
                        this.CatID = Conversions.ToInteger(this.Request.QueryString["CatID"]);
                        if (this.CatID == -1)
                        {
                            this.CatID = this._ddlDefaultCategory;
                        }
                    }
                }
                else
                {
                    string expression = Strings.Replace(Conversions.ToString(SharedFunctions.getCookieURLparam(this.PortalId, "CatID")), "CatID=", "", 1, -1, CompareMethod.Binary);
                    if (Versioned.IsNumeric(expression))
                    {
                        this.CatID = Conversions.ToInteger(expression);
                    }
                }
                if (!Conversions.ToBoolean(this.Settings["chkStaticCategory"]))
                {
                    catID = this.CatID;
                }
                if (((this.Request.QueryString["ProdID"] != null) & Conversions.ToBoolean(this.Settings["chkViewProdHide"])) & !this._SubMenuOnly)
                {
                    this.dlCategoryMenu.Visible = false;
                    this.dlRootMenu.Visible = false;
                    this.lblBreadcrumbs.Visible = false;
                }
                else if (!this.Page.IsPostBack)
                {
                    this._SelectedCategories = new Hashtable();
                    if (this.CatID >= 0)
                    {
                        this.GetSelectedCategories(this.CatID, ref this._SelectedCategories);
                        this.populateList(this.CatID, catID);
                    }
                    else
                    {
                        this.dlCategoryMenu.Visible = false;
                        this.dlRootMenu.Visible = false;
                        this.lblBreadcrumbs.Visible = false;
                    }
                    if (!this._SubMenuOnly)
                    {
                        this.phSecSep1.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtSectionSep"])));
                        this.phSecSep2.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtSectionSep2"])));
                        this.phSecSep2.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtSectionSep3"])));
                        this.ShowTreeMenu();
                        this.ShowAccordion();
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void populateList(int CatID, int StaticCatID)
        {
            CategoryController controller = new CategoryController();
            if (Versioned.IsNumeric(this._txtColumns))
            {
                this.dlCategoryMenu.RepeatColumns = Conversions.ToInteger(this._txtColumns);
                this.dlRootMenu.RepeatColumns = Conversions.ToInteger(this._txtColumns);
            }
            else
            {
                this.dlRootMenu.RepeatColumns = 4;
                this.dlCategoryMenu.RepeatColumns = 4;
            }
            if (!Conversions.ToBoolean(this.Settings["chkHideRootMenu"]) & !this._SubMenuOnly)
            {
                ArrayList list2;
                if (this._chkPatchWork)
                {
                    IEnumerator enumerator=null;
                    list2 = new ArrayList();
                    ArrayList list3 = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture(), -1, false, false);
                    string input = "";
                    try
                    {
                        enumerator = list3.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                            input = Strings.Replace(current.Message, "&lt;p&gt;&amp;#160;&lt;/p&gt;", "", 1, -1, CompareMethod.Binary);
                            if (input != "")
                            {
                                input = Regex.Replace(input, @"\s*", "");
                            }
                            if ((current.ProductCount > 0) | (input != ""))
                            {
                                list2.Add(current);
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator is IDisposable)
                        {
                            (enumerator as IDisposable).Dispose();
                        }
                    }
                }
                else
                {
                    list2 = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture(), 0, false, false);
                }
                if (list2 != null)
                {
                    this.dlRootMenu.DataSource = list2;
                    this.dlRootMenu.DataBind();
                }
                this.dlRootMenu.Visible = true;
                if (Conversions.ToString(this.Settings["txtRootCSS"]) != "")
                {
                    this.dlRootMenu.CssClass = Conversions.ToString(this.Settings["txtRootCSS"]);
                }
                if (Conversions.ToString(this.Settings["txtRootHeadHtml"]) != "")
                {
                    this.phRootHead.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtRootHeadHtml"])));
                }
            }
            else
            {
                this.dlRootMenu.Visible = false;
            }
            if ((CatID == 0) & Conversions.ToBoolean(this.Settings["chkHideWhenRoot"]))
            {
                this.dlCategoryMenu.Visible = false;
                this.lblBreadcrumbs.Visible = false;
            }
            else
            {
                this.lblBreadcrumbs.Visible = false;
                if (!this._chkHideSubMenu | !Conversions.ToBoolean(this.Settings["chkHideBreadCrumb"]))
                {
                    ArrayList aryList = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture(), StaticCatID, false, false);
                    if (aryList != null)
                    {
                        NB_Store_CategoriesInfo category;
                        this.dlCategoryMenu.Visible = true;
                        if (aryList.Count == 0)
                        {
                            category = controller.GetCategory(CatID, SharedFunctions.GetCurrentCulture());
                            if (category != null)
                            {
                                if (category.ParentCategoryID == 0)
                                {
                                    this.dlCategoryMenu.Visible = false;
                                }
                                else
                                {
                                    aryList = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture(), category.ParentCategoryID, false, false);
                                }
                            }
                        }
                        if (Conversions.ToBoolean(this.Settings["chkHideBreadCrumb"]) | this._SubMenuOnly)
                        {
                            this.lblBreadcrumbs.Visible = false;
                        }
                        else
                        {
                            string text = this.BuildBreadCrumbs(CatID, aryList);
                            if (text != "")
                            {
                                this.lblBreadcrumbs.Controls.Add(new LiteralControl(text));
                                this.lblBreadcrumbs.Visible = true;
                            }
                        }
                        if (this._chkHideSubMenu)
                        {
                            this.dlCategoryMenu.Visible = false;
                        }
                        else
                        {
                            if (Conversions.ToBoolean(this.Settings["chkSkipBlankCat"]))
                            {
                                IEnumerator enumerator2=null;
                                try
                                {
                                    enumerator2 = aryList.GetEnumerator();
                                    while (enumerator2.MoveNext())
                                    {
                                        category = (NB_Store_CategoriesInfo) enumerator2.Current;
                                        if (category.ProductCount == 0)
                                        {
                                            category.CategoryID = this.GetFirstNonEmptyChild(category.CategoryID);
                                        }
                                    }
                                }
                                finally
                                {
                                    if (enumerator2 is IDisposable)
                                    {
                                        (enumerator2 as IDisposable).Dispose();
                                    }
                                }
                            }
                            if (this._txtCSS != "")
                            {
                                this.dlCategoryMenu.CssClass = this._txtCSS;
                            }
                            if (this._txtSubHeadHtml != "")
                            {
                                string replacement = "";
                                if (aryList.Count > 0)
                                {
                                    replacement = ((NB_Store_CategoriesInfo) aryList[0]).ParentName;
                                }
                                else
                                {
                                    NB_Store_CategoriesInfo info3 = controller.GetCategory(CatID, SharedFunctions.GetCurrentCulture());
                                    if (info3 != null)
                                    {
                                        replacement = info3.CategoryName;
                                    }
                                    else
                                    {
                                        replacement = "Category " + CatID.ToString();
                                    }
                                }
                                this.phSubHead.Controls.Add(new LiteralControl(Strings.Replace(this._txtSubHeadHtml, "[TAG:PARENTNAME]", replacement, 1, -1, CompareMethod.Binary)));
                            }
                            this.dlCategoryMenu.DataSource = aryList;
                            this.dlCategoryMenu.DataBind();
                        }
                    }
                    else
                    {
                        this.dlCategoryMenu.Visible = false;
                    }
                }
            }
        }

        private string ReplaceLinkTokens(string NameTemplate, string Lefthtml, string RightHtml, NB_Store_CategoriesInfo itemInfo, string strHtmlLink)
        {
            string expression = "";
            expression = Strings.Replace(Lefthtml + Strings.Replace(NameTemplate, "[TAG:CATEGORYNAME]", itemInfo.CategoryName, 1, -1, CompareMethod.Binary) + RightHtml, "[TAG:PRODUCTCOUNT]", itemInfo.ProductCount.ToString(), 1, -1, CompareMethod.Binary);
            if (itemInfo.ImageURL == "")
            {
                expression = Strings.Replace(Strings.Replace(expression, "[TAG:IMAGE]", itemInfo.CategoryName, 1, -1, CompareMethod.Binary), "[TAG:IMAGEURL]", "", 1, -1, CompareMethod.Binary);
            }
            else
            {
                expression = Strings.Replace(Strings.Replace(expression, "[TAG:IMAGE]", "<img border=\"0\" src=\"" + base.StoreInstallPath + "makethumbnail.ashx?Image=" + DotNetNuke.Common.Globals.QueryStringEncode(@"productimages\" + Path.GetFileName(itemInfo.ImageURL)) + "&w=" + this._txtThumbnailSize + "&tabid=" + Conversions.ToString(this._TabId) + "\" alt=\"" + itemInfo.CategoryName + "\"/>", 1, -1, CompareMethod.Binary), "[TAG:IMAGEURL]", itemInfo.ImageURL, 1, -1, CompareMethod.Binary);
            }
            expression = Strings.Replace(Strings.Replace(expression, "[TAG:IMAGEURLTHUMB]", base.StoreInstallPath + "makethumbnail.ashx?Image=" + DotNetNuke.Common.Globals.QueryStringEncode(@"productimages\" + Path.GetFileName(itemInfo.ImageURL)) + "&w=" + this._txtThumbnailSize + "&tabid=" + Conversions.ToString(this._TabId), 1, -1, CompareMethod.Binary), "[TAG:LINK]", strHtmlLink, 1, -1, CompareMethod.Binary);
            if (itemInfo.CategoryID == this.CatID)
            {
                return Strings.Replace(expression, "[TAG:CATEGORYNAMECSS]", Strings.Replace(itemInfo.CategoryName, " ", "_", 1, -1, CompareMethod.Binary) + "sel", 1, -1, CompareMethod.Binary);
            }
            return Strings.Replace(expression, "[TAG:CATEGORYNAMECSS]", Strings.Replace(itemInfo.CategoryName, " ", "_", 1, -1, CompareMethod.Binary), 1, -1, CompareMethod.Binary);
        }

        private void ShowAccordion()
        {
            if (Conversions.ToBoolean(this.Settings["chkShowAccordionMenu"]))
            {
                CategoryController controller = new CategoryController();
                string text = "";
                if (Conversions.ToString(this.Settings["txtAccordionHeadHtml"]) != "")
                {
                    this.phTreeHead.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtAccordionHeadHtml"])));
                }
                ArrayList categories = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture());
                text = this.BuildAccordionMenu(categories, "", 0, -1);
                this.phTreeMenu.Controls.Add(new LiteralControl(text));
                SharedFunctions.IncludeScripts(this.PortalId, base.StoreInstallPath, this.Page, "categorymenujs.includes ", "categorymenustartupjs.includes", "categorymenucss.includes");
            }
        }

        private void ShowTreeMenu()
        {
            if (Conversions.ToBoolean(this.Settings["chkShowTreeMenu"]))
            {
                CategoryController controller = new CategoryController();
                string text = "";
                if (Conversions.ToString(this.Settings["txtTreeHeadHtml"]) != "")
                {
                    this.phTreeHead.Controls.Add(new LiteralControl(Conversions.ToString(this.Settings["txtTreeHeadHtml"])));
                }
                ArrayList categories = controller.GetCategories(this.PortalId, SharedFunctions.GetCurrentCulture());
                text = this.BuildTreeMenu(categories, "", 0, 0);
                this.phTreeMenu.Controls.Add(new LiteralControl(text));
                SharedFunctions.IncludeScripts(this.PortalId, base.StoreInstallPath, this.Page, "categorymenujs.includes", "categorymenustartupjs.includes", "categorymenucss.includes");
            }
        }

        protected virtual DataList dlCategoryMenu
        {
            get
            {
                return this._dlCategoryMenu;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                DataListItemEventHandler handler = new DataListItemEventHandler(this.dlCategoryMenu_ItemDataBound);
                if (this._dlCategoryMenu != null)
                {
                    this._dlCategoryMenu.ItemDataBound -= handler;
                }
                this._dlCategoryMenu = value;
                if (this._dlCategoryMenu != null)
                {
                    this._dlCategoryMenu.ItemDataBound += handler;
                }
            }
        }

        protected virtual DataList dlRootMenu
        {
            get
            {
                return this._dlRootMenu;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                DataListItemEventHandler handler = new DataListItemEventHandler(this.dlRootMenu_ItemDataBound);
                if (this._dlRootMenu != null)
                {
                    this._dlRootMenu.ItemDataBound -= handler;
                }
                this._dlRootMenu = value;
                if (this._dlRootMenu != null)
                {
                    this._dlRootMenu.ItemDataBound += handler;
                }
            }
        }

        protected virtual PlaceHolder lblBreadcrumbs
        {
            get
            {
                return this._lblBreadcrumbs;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblBreadcrumbs = value;
            }
        }

        protected virtual PlaceHolder phRootHead
        {
            get
            {
                return this._phRootHead;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phRootHead = value;
            }
        }

        protected virtual PlaceHolder phSecSep1
        {
            get
            {
                return this._phSecSep1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phSecSep1 = value;
            }
        }

        protected virtual PlaceHolder phSecSep2
        {
            get
            {
                return this._phSecSep2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phSecSep2 = value;
            }
        }

        protected virtual PlaceHolder phSecSep3
        {
            get
            {
                return this._phSecSep3;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phSecSep3 = value;
            }
        }

        protected virtual PlaceHolder phSubHead
        {
            get
            {
                return this._phSubHead;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phSubHead = value;
            }
        }

        protected virtual PlaceHolder phTreeHead
        {
            get
            {
                return this._phTreeHead;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phTreeHead = value;
            }
        }

        protected virtual PlaceHolder phTreeMenu
        {
            get
            {
                return this._phTreeMenu;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._phTreeMenu = value;
            }
        }
    }
}

